home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Files
/
CatInfo.cp
next >
Wrap
Text File
|
1997-06-28
|
4KB
|
201 lines
// CatInfo.cp
#ifndef CatInfo_h
#include "CatInfo.h"
#endif
#ifndef FileNotFoundError_h
#include "FileNotFoundError.h"
#endif
#ifndef DirectoryNotFoundError_h
#include "DirectoryNotFoundError.h"
#endif
#ifndef HardwareVolumeLockError_h
#include "HardwareVolumeLockError.h"
#endif
#ifndef SoftwareVolumeLockError_h
#include "SoftwareVolumeLockError.h"
#endif
#ifndef FileLockError_h
#include "FileLockError.h"
#endif
#ifndef FilePermissionError_h
#include "FilePermissionError.h"
#endif
#ifndef NotADirectoryError_h
#include "NotADirectoryError.h"
#endif
CatInfo::CatInfo()
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
}
CatInfo::CatInfo( const FileLocation& target )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( target );
}
CatInfo::CatInfo( ::Directory directory )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory );
}
CatInfo::CatInfo( ::Directory directory, ConstPString name )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory, name );
}
CatInfo::CatInfo( ::Directory directory, int16 index )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory, index );
}
CatInfo::CatInfo( const CatInfo& source )
: CInfoPBRec( source ),
location( source.location )
{
hFileInfo.ioNamePtr = location.name;
}
void CatInfo::operator=( const CatInfo& source )
{
static_cast< CInfoPBRec& >( *this ) = source;
location = source.location;
hFileInfo.ioNamePtr = location.name;
}
void CatInfo::Get()
{
hFileInfo.ioVRefNum = location.Volume().RefNum();
hFileInfo.ioDirID = location.ParentID().Number();
hFileInfo.ioFDirIndex = 0;
ThrowError( PBGetCatInfoSync( this ) );
Assert( hFileInfo.ioVRefNum == location.vRefNum );
Assert( hFileInfo.ioFlParID == location.parID );
}
void CatInfo::Get( const FileLocation& target )
{
location = target;
Get();
}
void CatInfo::Get( ::Directory directory )
{
hFileInfo.ioVRefNum = directory.Volume().RefNum();
hFileInfo.ioDirID = directory.ID().Number();
hFileInfo.ioFDirIndex = -1;
ThrowError( PBGetCatInfoSync( this ) );
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
}
void CatInfo::Get( ::Directory directory, ConstPString name )
{
location.Set( directory, name );
Get();
}
void CatInfo::Get( ::Directory directory, int16 index )
{
Assert( index > 0 );
hFileInfo.ioVRefNum = directory.Volume().RefNum();
hFileInfo.ioDirID = directory.ID().Number();
hFileInfo.ioFDirIndex = index;
ThrowError( PBGetCatInfoSync( this ) );
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
Assert( directory.Volume().RefNum() == location.vRefNum );
Assert( directory.ID().Number() == location.parID );
}
void CatInfo::Set()
{
hFileInfo.ioVRefNum = location.Volume().RefNum();
hFileInfo.ioDirID = location.ParentID().Number();
ThrowError( PBSetCatInfoSync( this ) );
}
void CatInfo::Set( const FileLocation& target )
{
location = target;
Set();
}
::Directory CatInfo::AsDirectory() const
{
if ( !IsDirectory() )
throw NotADirectoryError( noErr );
return ::Directory( location.Volume(), Directory().ID() );
}
void CatInfo::Up()
{
Assert( !IsRoot() );
if ( IsRoot() )
ThrowError( dirNFErr );
Get( location.Parent() );
}
void CatInfo::Down( ConstPString child )
{
Assert( IsDirectory() );
if ( !IsDirectory() )
throw NotADirectoryError( noErr );
location.SetParentID( Directory().ID() );
location.SetName( child );
Get();
}
void CatInfo::Sideways( ConstPString sibling )
{
location.SetName( sibling );
Get();
}
void CatInfo::SetLabel( uint8 label )
{
Assert( label < 8 );
hFileInfo.ioFlFndrInfo.fdFlags =
( hFileInfo.ioFlFndrInfo.fdFlags & ~kColor )
| ( label << 1 );
}
void CatInfo::ThrowError( OSErr error )
{
if ( error == noErr )
return;
switch ( error )
{
case fnfErr: throw FileNotFoundError( error );
case dirNFErr: throw DirectoryNotFoundError( error );
case wPrErr: throw HardwareVolumeLockError( error );
case vLckdErr: throw SoftwareVolumeLockError( error );
case fLckdErr: throw FileLockError( error );
case afpAccessDenied: throw FilePermissionError( error );
}
throw FileError( error );
}